<?php
include('includes/basic.php');
   $temp=$_POST['temp_id'];
	
   $c=mysql_query("select * from customer_master where customer_id=$userId");
   $c1=mysql_fetch_array($c);
   extract($c1);
	$sender=$c1['user_name'];

   $sql=mysql_query("select * from templates where content_id=$temp");
   while($result=mysql_fetch_array($sql))
   {
	$r=$result['content'];
	$sub=$result['title'];
	
   }
      
		foreach($_POST['emails'] as $a => $h) 
		 {
		    
			//$sql1="select * from client_master where client_id='".$h."'";
			//$r1=mysql_query($sql1);
			//$row15=mysql_fetch_array($r1);
			//extract($row15);
			$to=$h;
			sleep(8);
			
			
		   	$subject=$sub;
			$massage=$r;
                    $headers = 'MIME-Version: 1.0' . "\r\n";
					$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
					$headers .= 'From: '.$sender. "\r\n";
					
					
					
					$mail=mail($to, $subject, $massage, $headers);
					  
					  if($mail)
						  {
							header('Location:view-templates.php');
						  }
					  else
						  {
							echo "no";
							
						  }
						  
					
				 
		
     }
	
?>                 